<%@page import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<div class="header">
	<h2>
		微信服务号参数设置<span><font color="red">（* 为必填项）</font> </span>
	</h2>
</div>
<form action="app/appConfig/save" id="formAppConfig" method="post">

	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">是否启用：</td>
				<td class="td2"><input type="radio" id="wechatMpEnable1"
					name="wechatMpEnable" value="1" /><label for="wechatMpEnable1">是</label>

					<input type="radio" id="wechatMpEnable2" name="wechatMpEnable"
					value="0" /><label for="wechatMpEnable2">否</label>
				</td>
			</tr>
			<tr>
				<td class="td1">服务号二维码：</td>
				<td class="td2"><isperp:photoUploader imgName="wechatMpQrcode"
						cutType="0" imgWidth="140" imgHeight="140"
						imgSrc="${wechatMpQrcode}" id="wechatMpQrcode" imgPath="wechatMpQrcode"
						imgFormat="png/gif/jpg"></isperp:photoUploader>
				</td>
			</tr>

			<tr>
				<td class="td1">微信Token：</td>
				<td class="td2"><input type="text" id="txtWechatMpToken"
					name="wechatMpToken" value="${wechatMpToken}" maxlength="50"
					style="width:30%" class="required" /></td>
				</td>
			</tr>
			<tr>
				<td class="td1">微信AppId：</td>
				<td class="td2"><input type="text" id="txtWechatMpAppId"
					name="wechatMpAppId" value="${wechatMpAppId}" maxlength="50"
					style="width:30%" class="required" /></td>
			</tr>
			<tr>
				<td class="td1">微信AppSecret：</td>
				<td class="td2"><input type="text" id="txtWechatMpAppSecret"
					name="wechatMpAppSecret" value="${wechatMpAppSecret}" maxlength="50"
					style="width:30%" class="required" /></td>
			</tr>
			<tr>
				<td class="td1">ACCESS_TOKEN：</td>
				<td class="td2"><label id="lbAccessToken">${wechatMpAccessToken}</label><br>
					<input type="button" onclick="resetAccessToken();" value="重置">(有效期为7200秒)
				</td>
			</tr>
		</tbody>
	</table>
	<div class="header">
		<h2>微信服务台工作时间设置</h2>
	</div>
	<table class=" form-table">
		<tr>
			<td class="td1">工作日设定：</td>
			<td class="td2"><input type="checkbox" id="wechatMpWorkWeek1"
				name="wechatMpWorkWeek1" value="1" /><label for="wechatMpWorkWeek1">星期一</label>
				<input type="checkbox" id="wechatMpWorkWeek2" name="wechatMpWorkWeek2"
				value="1" /><label for="wechatMpWorkWeek2">星期二 </label> <input
				type="checkbox" id="wechatMpWorkWeek3" name="wechatMpWorkWeek3"
				value="1" /><label for="wechatMpWorkWeek3">星期三 </label> <input
				type="checkbox" id="wechatMpWorkWeek4" name="wechatMpWorkWeek4"
				value="1" /><label for="wechatMpWorkWeek4">星期四</label> <input
				type="checkbox" id="wechatMpWorkWeek5" name="wechatMpWorkWeek5"
				value="1" /><label for="wechatMpWorkWeek5">星期五</label> <input
				type="checkbox" id="wechatMpWorkWeek6" name="wechatMpWorkWeek6"
				value="1" /><label for="wechatMpWorkWeek6">星期六</label> <input
				type="checkbox" id="wechatMpWorkWeek7" name="wechatMpWorkWeek7"
				value="1" /><label for="wechatMpWorkWeek7">星期日</label>
			</td>
		</tr>
		<tr>
			<td class="td1">工作时间：</td>
			<td class="td2">上午 <input type="time" name="wechatMpWorkAmBegin"
				id="wechatMpAmBegin" value="${wechatMpWorkAmBegin}" class="time">
				~ <input type="time" name="wechatMpWorkAmEnd" id="wechatMpWorkAmEnd"
				value="${wechatMpWorkAmEnd}" class="time">
				<p style="padding-top:2px">
					下午 <input type="time" name="wechatMpWorkPmBegin"
						id="wechatMpWorkPmBegin" value="${wechatMpWorkPmBegin}" class="time">
					~ <input type="time" name="wechatMpWorkPmEnd" id="wechatMpWorkPmEnd"
						value="${wechatMpWorkPmEnd}" class="time">
			</td>
		</tr>
		<tr>
			<td class="td1">非工作时间自动回复：</td>
			<td class="td2">
				<p>请输入文本，支持参数:openid,config(配置项内容)</p> <textarea
					id="txtWechatMpNoworkTimeNotice" name="wechatMpNoworkTimeNotice"
					class="required" style="width:80%;height:50px">${wechatMpNoworkTimeNotice}</textarea>
			</td>
		</tr>
	</table>

	<div class="header">
		<h2>微信消息通知</h2>
	</div>
	<table class=" form-table">

		<tr>
			<td class="td1">创建工单通知：</td>
			<td class="td2"><textarea id="wechatMpCreateIncidentNotice"
					name="wechatMpCreateIncidentNotice" class="required"
					style="width:80%;height:50px">${wechatMpCreateIncidentNotice}</textarea>
			</td>
		</tr>



	</table>
	<div class="header">
		<h2>全局响应事件设置</h2>
	</div>
	<table class=" form-table">

		<tr>
			<td class="td1">用户注册提示：</td>
			<td class="td2">
				<p>请输入文本，支持参数:openid,config(配置项内容)</p> <textarea
					id="txtWechatMpRegisterNotice" name="wechatMpRegisterNotice"
					class="required" style="width:80%;height:50px">${wechatMpRegisterNotice}</textarea>
			</td>
		</tr>
		<tr>
			<td class="td1">用户审核中提示：</td>
			<td class="td2">
				<p>请输入文本，支持参数:openid,config(配置项内容)</p> <textarea
					id="wechatMpRegisterApprovalNotice"
					name="wechatMpRegisterApprovalNotice" class="required"
					style="width:80%;height:50px">${wechatMpRegisterApprovalNotice}</textarea>
			</td>
		</tr>
		<tr>
			<td class="td1">用户被禁用提示：</td>
			<td class="td2">
				<p>请输入文本，支持参数:openid,config(配置项内容)</p> <textarea
					id="wechatMpRegisterInvalidNotice" name="wechatMpRegisterInvalidNotice"
					class="required" style="width:80%;height:50px">${wechatMpRegisterInvalidNotice}</textarea>
			</td>
		</tr>


		<tr>
			<td class="td1">用户订阅响应：</td>
			<td class="td2">
				<p style="font-weight: bold;">支持参数:openid,contextUrl,config(配置项内容)</p>
				<div id="messageContentTableDiv">
					<input type="button" onclick="createMessageContentRow()"
						class="sbutton" value="添加图文项">
					<table class="search-table" id="messageContentTable">
						<tr>
							<th width="120">名称(<span class="red">*</span>)
							<th width="200">描述</th>
							<th width="300">图片地址</th>
							<th width="200">url</th>
							<th width="30">操作</th>
						</tr>
						<c:forEach items="${newsList }" var="article">
							<tr>
								<td><input type="text" name="messageContentTitle"
									value=${article.title }>
								</td>
								<td><input type="text" name="messageContentDesc"
									value=${article.description }>
								</td>
								<td><input type="text" name="messageContentPicurl"
									value=${article.picurl }> <a class="nui-txt-link"
									href="">上传</a></td>
								<td><input type="text" name="messageContentUrl"
									value=${article.url }></td>
								<td><span class="ui-icon ui-icon-trash"
									onclick="removeMessageContentRow(this)"></span>
								</td>
							</tr>
						</c:forEach>
					</table>
				</div></td>
		</tr>

		<tr>
			<td class="td1">取消订阅响应：</td>
			<td class="td2">
				<p>请输入文本，支持参数:openid,config(配置项内容)</p> <textarea
					id="txtWechatMpSubscribeNotice" name="wechatMpSubscribeNotice"
					class="required" style="width:80%;height:50px">${wechatMpSubscribeNotice}</textarea>
			</td>
		</tr>

	</table>
</form>
<table class=" form-table">
	<tbody>
		<tr>
			<td class="td1"></td>
			<td class="td2"><button type="submit" id="btnSaveAppConfig"
					class="nui-mainbtn" onclick="btnSaveAppConfigOnclick();"
					name="btnSaveAppConfig" value="保存">&nbsp;&nbsp;&nbsp;保存&nbsp;&nbsp;&nbsp;</button>
			</td>
		</tr>

	</tbody>
</table>

<script type="text/javascript">
	var rowTemplate = '<tr>' + '<td><input type="text" name="messageContentTitle">' + '</td>' + '<td><input type="text" name="messageContentDesc">' + '</td>' + '<td><input type="text" name="messageContentPicurl">' + '	<a class="nui-txt-link" href="">上传</a></td>' + '<td><input type="text" name="messageContentUrl"></td>' + '<td><span class="ui-icon ui-icon-trash"' + '	onclick="removeMessageContentRow(this)"></span>' + '</td>' + '</tr>';

	$("input[name=wechatMpWorkWeek1][value=${wechatMpWorkWeek1}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek2][value=${wechatMpWorkWeek2}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek3][value=${wechatMpWorkWeek3}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek4][value=${wechatMpWorkWeek4}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek5][value=${wechatMpWorkWeek5}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek6][value=${wechatMpWorkWeek6}]").attr("checked", 'checked');
	$("input[name=wechatMpWorkWeek7][value=${wechatMpWorkWeek7}]").attr("checked", 'checked');

	$("input[name=wechatMpEnable][value=${wechatMpEnable}]").attr("checked", 'checked');

	function createMessageContentRow() {
		$("#messageContentTable").append(rowTemplate);
	}

	function removeMessageContentRow(obj) {
		$(obj).parent().parent().remove();
	}
	function btnSaveAppConfigOnclick() {
		isperp.showLoading();
		isperp.submitForm({
			formId : "formAppConfig",
			success : function(data) {
				if (data.success) {

					isperp.hideLoading();
					isperp.alert("保存成功！");
				} else {
					isperp.alert(data.tata);
				}
			},
			error : function() {

				isperp.hideLoading();
				isperp.alert("保存失败！");
			}
		});
	}

	function resetAccessToken() {
		$.post("app/appConfig/resetAccessToken", function(data) {
			$("#lbAccessToken").text(data.data);
			isperp.alert("重置成功");

		});
	}
</script>










